<html>
    <!-- Copyright 2010  Jacob Brunson  (email : wp-jacob.gpl.license@jacobbrunson.com )

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-->
<head> 
    <title>Demo</title>
    <script type="text/javascript" src="lib/air/AIRAliases.js"></script>
    <script type="text/javascript" src="lib/air/AIRIntrospector.js"></script>
    <script type="text/javascript">
    
    var total_bytes = 0;
    var total_bytes_read = 0;
    var percentElement;

    function startapp()
    {
        percentElement = document.getElementById('percent');
        file_obj = new air.File('file:///home/jacob/Documents/bigfile.txt');
        total_bytes = file_obj.size;
        fstream = new air.FileStream();
        fstream.addEventListener(air.ProgressEvent.PROGRESS, readFile);
        fstream.addEventListener(air.Event.COMPLETE, doneReadingFile);
        fstream.openAsync(file_obj, air.FileMode.READ);
    }

    function readFile(event)
    {
        while (event.target.bytesAvailable > 0) {
            bite = event.target.readByte();
            total_bytes_read++;
            if (total_bytes_read % 512 == 0) {
                air.trace("Reading file", total_bytes_read/total_bytes);
                percentElement.innerHTML = Math.round((total_bytes_read/total_bytes)*100) + "%";
            }
        }
    }

    function doneReadingFile(event)
    {
        air.trace("Done Reading File");
        event.target.close();
    }
    
    </script>

</head> 
<body onload="startapp();" >
    <div id="percent"></div>
</body> 
</html>